#include<bits/stdc++.h>
//~ #define p 998244353
//~ #define int long long
using namespace std;
template<typename T>inline void read(T &x){
	T f=1;char ch=getchar();x=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
	x*=f;
}
template<typename T>inline void write(T x){
	if(x<0){putchar('-');x=-x;}
	if(x<10){putchar(x+'0');return;}
	write(x/10);
	putchar(x%10+'0');
}
int a[100010];
int n;
int f[2010][2010][2];//dep=i;lst~k=j;col=k;
void solve2(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
	}
	memset(f,0,sizeof(f));
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++){
			f[i][j][0]=max(f[i][j][0],f[i-1][j][0]+((a[i]==a[i-1])?a[i]:0));
			f[i][j][1]=max(f[i][j][1],f[i-1][j][1]+((a[i]==a[i-1])?a[i]:0));
		}
		for(int j=1;j<i;j++){
			//~ if(a[i]==a[j])cout<<"!!!\n";
			f[i][i-1][0]=max(f[i][i-1][0],f[i-1][j][1]+((a[i]==a[j])?a[i]:0));
			f[i][i-1][1]=max(f[i][i-1][1],f[i-1][j][0]+((a[i]==a[j])?a[i]:0));
		}
	}
	//~ for(int i=1;i<=n;i++){
		//~ for(int j=1;j<=n;j++){
			//~ cout<<f[i][j][0]<<";"<<f[i][j][1]<<" ";
		//~ }
		//~ cout<<endl;
	//~ }
	write(f[n][n-1][0]);putchar('\n');
}
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;
	read(T);
	while(T--)
		solve2();
	return 0;
}
//20090626
/*

3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4

 
*/
